package com.carserver.service;

import com.carserver.pojo.Buy_detail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

public interface Buy_detailDao extends JpaRepository<Buy_detail,Integer> {
    @Modifying
    @Transactional
    @Query(value = "delete from buy_detail where user_id=:ID",nativeQuery = true)
    void deleteAllByUser_id(@Param("ID") Integer id);

    @Query(value = "select * from buy_detail where user_id=:ID",nativeQuery = true)
    List<Buy_detail> findBuy_detailByUser_id(@Param("ID") Integer id);

    @Modifying
    @Transactional
    @Query(value = "delete from buy_detail where car_number=?2 and user_id=?1 ",nativeQuery = true)
    void deleteBuy_detailByUser_idAndCarPartsName(Integer user_id,String name);

    @Query(value = "select * from buy_detail where car_number=?2 and user_id=?1 ",nativeQuery = true)
    Buy_detail findBuy_detailByUser_idAndCarNumber(Integer user_id,String name);
}
